/** @namespace */
var agr = agr || {};


/** @namespace */
agr.Interface = function() {
    'use strict';

    var regex = /.*\?q=([^#]+)/;

    /** @scope agr.Interface */
    return {
        /**
         * parses url query string to object
         *
         * @return {Object} application state object.
         */
        getStateFromURL: function(url) {
            var result = regex.exec(url);

            if (result && result[1]) {
                try {
                    return JSON.parse(window.decodeURIComponent(result[1]));
                } catch (e) {
                    return {};
                }
            }
            return {};
        },
            /**
             * creates url query string from object
             *
             * @param {Object} o any object.
             */
            makeQueryString: function(o) {
                if (o) {
                    return 'q=' + window.encodeURIComponent(JSON.stringify(o));
                }
                return null;
            },
            /**
             * creates url query string from object
             *
             * @param {Object} o any object.
             */
            makeQueryURL: function(page, o) {
                if (o) {
                    return page + '.html?q=' + window.encodeURIComponent(JSON.stringify(o));
                }
                return null;
            }
    };
}();
